package com.masterclient.app.modules.search.adapter;

import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.masterclient.app.R;
import com.masterclient.app.modules.search.SearchGoodBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.Utils;
import com.eoner.baselibrary.utils.ViewTransformUtil;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * 作者：sean
 * 创建时间：2017/6/23 16:32
 * 功能说明：
 */

public class SearchGoodRecyclerAdapter extends BaseQuickAdapter<SearchGoodBean.DataBean.ShProductsBean, BaseViewHolder> {
//    @BindView(R.id.iv_goods)
//    ImageView ivGoods;
//    @BindView(R.id.tv_new_goods_promotion)
//    TextView tvNewGoodsPromotion;
//    @BindView(R.id.tv_sub_title)
//    TextView tvSubTitle;
//    @BindView(R.id.tv_title)
//    TextView tvTitle;
//    @BindView(R.id.tv_price_now)
//    TextView tvPriceNow;
//    @BindView(R.id.tv_price_older)
//    TextView tvPriceOlder;

    public SearchGoodRecyclerAdapter() {
        super(R.layout.item_search_good);
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchGoodBean.DataBean.ShProductsBean item) {

        ViewTransformUtil.glideImageView(mContext,item.getSh_image(),(ImageView) helper.getView(R.id.iv_goods),
                new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0, RoundedCornersTransformation.CornerType.TOP),
                R.mipmap.defaults,ScreenUtils.dp2px(165), ScreenUtils.dp2px(165));

        helper.setText(R.id.tv_sub_title,item.getSh_name());
        helper.setText(R.id.tv_title,item.getSh_subname());
        //if("".equals(item.getsh_))
        if("2".equals(item.getSh_type())){
            helper.setText(R.id.tv_price_now,item.getSh_integral_price() + "金币");
        }else{
            helper.setText(R.id.tv_price_now,item.getSh_show_price());
        }
        Utils.setDin(helper.getView(R.id.tv_price_now),mContext);

        TextView tv_bofang = helper.getView(R.id.tv_bofang);
        tv_bofang.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/iconfont.ttf"));
//        if("1".equals(item.getSh_has_video())){
//            helper.getView(R.id.rl_video).setVisibility(View.VISIBLE);
//        }else {
//            helper.getView(R.id.rl_video).setVisibility(View.GONE);
//        }

//        if (TextUtils.isEmpty(item.getSh_line_price())||Double.valueOf(item.getSh_line_price()).doubleValue() == Double.valueOf(item.getSh_show_price()).doubleValue()) {
//            helper.getView(R.id.tv_price_older).setVisibility(View.INVISIBLE);
//        }else {
            //helper.getView(R.id.tv_price_older).setVisibility(View.VISIBLE);
//            helper.setText(R.id.tv_price_older,"¥"+item.getSh_line_price());
//        }

        ((TextView)helper.getView(R.id.tv_price_older)).setPaintFlags(Paint. STRIKE_THRU_TEXT_FLAG| Paint.ANTI_ALIAS_FLAG);
        ImageView ivActivity = helper.getView(R.id.iv_activity);

        ImageView ivTagNew = helper.getView(R.id.iv_tag_new);
        View ivShouqing = helper.getView(R.id.ll_shouqing);
        LinearLayout ll_user = helper.getView(R.id.ll_user);
        LinearLayout ll_earn = helper.getView(R.id.ll_earn);
        TextView tv_price = helper.getView(R.id.tv_price);
        TextView tv_money_earn = helper.getView(R.id.tv_money_earn);

        Utils.setDin(tv_money_earn,mContext);
        if(TextUtils.isEmpty(item.getSh_partner_commission())||0==Double.valueOf(item.getSh_partner_commission())){
            tv_money_earn.setVisibility(View.GONE);
        }else {
            tv_money_earn.setVisibility(View.VISIBLE);
            tv_money_earn.setText("赚"+item.getSh_partner_commission());
        }
//        if(0==Double.valueOf(item.getSh_partner_commission())){
//            ll_user.setVisibility(View.VISIBLE);
//            ll_earn.setVisibility(View.GONE);
//        }else {
//            tv_price.setText("¥"+item.getSh_show_price());
//            tv_money_earn.setText("赚"+item.getSh_partner_commission());
//            ll_user.setVisibility(View.GONE);
//            ll_earn.setVisibility(View.VISIBLE);
//        }
//
        if(Long.valueOf(item.getSh_stock())<=0){
            ivShouqing.setVisibility(View.VISIBLE);
        }else {
            ivShouqing.setVisibility(View.GONE);
        }

        if("1".equals(item.getSh_is_new())){
            ivTagNew.setVisibility(View.VISIBLE);
        }else {
            ivTagNew.setVisibility(View.GONE);
        }
//
//        if(item.getSh_label()!=null
//                && !TextUtils.isEmpty(item.getSh_label().getSh_icon_height())
//                &&!TextUtils.isEmpty(item.getSh_label().getSh_icon_width())) {
//            App.picasso.load(item.getSh_label().getSh_icon()).fit().into(ivActivity);
//            ivActivity.setVisibility(View.VISIBLE);
//            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivActivity.getLayoutParams();
//            params.height = ScreenUtils.dp2px(Integer.valueOf(item.getSh_label().getSh_icon_height()) / 2*0.8f);
//            params.width = ScreenUtils.dp2px(Integer.valueOf(item.getSh_label().getSh_icon_width()) / 2*0.8f);
//            switch (item.getSh_label().getSh_location()) {
//                case "left_top":
//                    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
//                    break;
//                case "right_top":
//                    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
//                    break;
//                case "left_bottom":
//                    params.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.iv_goods);
//                    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
//                    params.setMargins(ScreenUtils.dp2px(7), 0, 0, ScreenUtils.dp2px(7));
//                    break;
//                case "right_bottom":
//                    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
//                    params.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.iv_goods);
//                    params.setMargins(0, 0, 0,0);
//                    break;
//            }
//            ivActivity.setLayoutParams(params);
//        }else {
//            ivActivity.setVisibility(View.GONE);
//        }
    }
}
